#coding=utf-8
'''
Created on 2013年8月30日

@author: xuben

心跳
'''

from SocketService import gameSocketService
import BasicThread
import Command
import time

#角色标识, 用于心跳包发送
pkey = ''
#心跳线程实例
heartBeat = None

def start():
    global heartBeat
    if heartBeat == None:
        heartBeat = HeartBeat(name="heartBeat")
    heartBeat.startThread()

def pause():
    global heartBeat
    if heartBeat != None:
        heartBeat.pauseThread()

class HeartBeat(BasicThread.BasicThread):
    
    def callback(self):
        time.sleep(60)
        command = Command.HEART_BEAT
        params = 'pkey=' + str(pkey)
        gameSocketService.send(command, params)